package controller;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import model.Login;

public  class LoginDao implements ContratoLogin{
	
	private EntityManager em = null;

	public void setEm(EntityManager em) {
		this.em = em;
	}

	@Override
	public void inserir(Login login) {
		em.persist(login);
		
	}

	@Override
	public void alterar(Login login) {
		em.merge(login);
		
	}

	@Override
	public void excluir(Login login) {
		em.remove(login);
		
	}

	@Override
	public Login ObterLoginPeloID(int login) {
		return em.find(Login.class, login);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Login> obterLogins() {
		String s = "SELECT l FROM " + Login.class.getName() + " l ";
		Query query = em.createQuery(s);
		return query.getResultList();
	}

}
